630. 课程表 III
为保证权益,题目请参考 630. 课程表 III(From LeetCode).
解决方案1
Python
python
# 630. 课程表 III
# https://leetcode-cn.com/problems/course-schedule-iii/
################################################################################
from typing import List
import heapq
class Solution:
def scheduleCourse(self, courses: List[List[int]]) -> int:
courses.sort(key=lambda x: x[1])
que = []
total = 0
for t, d in courses:
if total + t <= d:
total += t
heapq.heappush(que, -t)
else:
if len(que) != 0 and -que[0] > t:
total = total + que[0] + t
heapq.heappop(que)
heapq.heappush(que, -t)
return len(que)
################################################################################
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32